package com.blank;

import com.blank.pojo.bo.Book;
import com.blank.service.BookService;
import com.blank.service.Impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * @author BLANK
 * @date 2020/11/19
 */
@WebServlet("/BookSelectPage")
public class BookSelectPage extends HttpServlet {

    private BookService bookService =new BookServiceImpl();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String page =request.getParameter("page");
        System.out.println(page);
    int pageNum;
    if(page==null){
        page="1";
    }
        //System.out.println();
    pageNum=Integer.parseInt(page);
        try {
            List<Book> list=bookService.selectBookPage(pageNum,3);
            System.out.println(pageNum);
            int num=bookService.countBookList();
            request.getSession().setAttribute("list",list);
            request.getSession().setAttribute("num",num);
            request.getRequestDispatcher("WEB-INF/jsp/BookListJsp.jsp").forward(request,response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
